<?php
require_once('functions.php');

$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : 0;
if($act == 1)
{
	session_destroy();
	header("Location: index.php");
}
$username = isset($_REQUEST['username']) ? $_REQUEST['username'] : "";
$password = isset($_REQUEST['password']) ? $_REQUEST['password'] : "";
if (empty($username) || empty($password)) {
	$template->assign("message",_MSG_LOGIN_TO_PLAY_GAME);
	$template->display("nologin.tpl");
}else if(strlen($username) > 30 || strlen($password) > 50){
	$template->assign("message",_MSG_WRONG_LOGIN);
	$template->display("nologin.tpl");
}else {
	$database->set_query("SELECT id, username, fullname FROM member WHERE username='" . mysql_real_escape_string($username) . "' AND password=MD5('" . mysql_real_escape_string($password) . "')");
	$member = $database->get_object();
	if($member)
	{
		$session->set("member_id", $member->id);
		$session->set("member_fullname", !empty($member->fullname) ? $member->fullname : $member->username);		
		header("Location: index.php");
	}
	else
	{
		$template->assign("message",_MSG_WRONG_LOGIN);
		$template->display("nologin.tpl");
	}
}
?>
